﻿@{
    ViewBag.Title = "UpdatePassword";
    Layout = "~/Areas/Students/Views/Shared/_Layout.cshtml";
}

<div class="am-cf am-padding">
    <div class="am-fl am-cf">
        <strong class="am-text-primary am-text-lg">修改密码</strong> / <small>UpdatePassword</small>
    </div>
</div>


<div class="am-g am-padding-lg" ng-controller="AppCtrl">
    <form class="am-form am-form-horizontal" id="form" method="POST" action="" style="width: 700px">
        <div class="am-form-group">
            <label for="caption" class="am-u-sm-2 am-form-label">原始密码*</label>
            <div class="am-u-sm-10">
                <input type="password" id="p0" placeholder="请输入原始密码" required maxlength="50"/>
            </div>
        </div>
        <div class="am-form-group">
            <label for="caption" class="am-u-sm-2 am-form-label">新密码*</label>
            <div class="am-u-sm-10">
                <input type="password" id="p1" placeholder="请输入新密码（最少6个字符）" required maxlength="50"/>
            </div>
        </div>
        <div class="am-form-group">
            <label for="caption" class="am-u-sm-2 am-form-label">确认密码*</label>
            <div class="am-u-sm-10">
                <input type="password" id="p2" name="password" placeholder="请再次输入" required maxlength="50"/>
            </div>
        </div>

        <div class="am-form-group am-cf">
            <div id="button" class="am-fr am-btn am-btn-primary am-radius">提交</div>
        </div>
    </form>
</div>

@section scripts{
    <script>
        $(function() {
            $("#button").click(function() {

                $.ajax({
                    url: "/students/log/TestPassword",
                    data: {
                        oldpassword: $("#p0").val()
                    },
                    success: function(res) {
                        if (res == 0) {
                            alert("原始密码错误");
                        } else {
                            if ($("#p2").val() == $("#p1").val()) {
                                $.ajax({
                                    url: $("form").submit(),
                                    data: { password: $("#p2").val() }
                                });
                            } else {
                                alert("两次新密码输入不同！");
                            }
                        }
                    }
                });

            });
        });
    </script>
}